<?php

namespace App\Model;

use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
//use Laravel\Passport\HasApiTokens;
use Zizaco\Entrust\Traits\EntrustUserTrait;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
/**
 * App\Model\Admin
 *
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Model\Role[] $roles
 * @mixin \Eloquent
 * @property integer $id
 * @property string $password
 * @property string $number
 * @property string $remember_token
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @property string $deleted_at
 * @property-read \App\Model\User $user
 * @method static \Illuminate\Database\Query\Builder|\App\Model\Admin whereId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Model\Admin wherePassword($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Model\Admin whereNumber($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Model\Admin whereRememberToken($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Model\Admin whereCreatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Model\Admin whereUpdatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Model\Admin whereDeletedAt($value)
 * @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
 * @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $unreadNotifications
 */
class Admin extends Model implements AuthenticatableContract, \Illuminate\Contracts\Auth\CanResetPassword
{

    use EntrustUserTrait, Authenticatable, Notifiable, SoftDeletes, CanResetPassword;

    protected $table = 'admin';

    protected $guarded = [];

    protected $hidden = [
        'password',
        'remember_token'
    ];

    protected $appends = [
        'repair_count'
    ];

    public function roles()
    {
        return $this->belongsToMany('App\Model\Role', 'role_user');
    }

    public function user()
    {
        return $this->belongsTo('App\Model\User', 'number', 'number');
    }

    public function repairOrders()
    {
        return $this->hasMany('App\Model\Repair', 'operator_id');
    }

    public function getRepairCountAttribute()
    {
        return $this->repairOrders()->where('status', 2)->count();
    }


}
